#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc_rsp_beta.info <<'%EOF%'
   cc_rsp_beta
   -----------
   Molecule:         HF in C2
   Wave Function:    CCS, CCSD / 6-31G**
   Test Purpose:     Static first hyperpolarizabilities and
                     first hyperpolarizability dispersion coefficients.
                     Tests .AVERAGE and .NOBMAT options
%EOF%

#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > cc_rsp_beta.mol <<'%EOF%'
BASIS
6-31G**
Hydrogen flourid
small test basis
    2    1  Y         1.00D-15
        9.0   1    
F     0.0000000000000000  0.0000000000000000 1.76320000000000000      
        1.0   1
H     0.0000000000000000  0.0000000000000000 0.00000000000000000      
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc_rsp_beta.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTIONS
**INTEGRAL
.DIPLEN
**WAVE FUNCTIONS
.TITLE
  first hyperpolarizability for the HF molecule
  for CCS and CCSD wavefunctions compute:
  - parallel (beta_|| ) and orthogonal averages (beta_|_)
  - A & B coefficients  (2. and 4. order dispersion coefficients)
.CC
*SCF INPUT 
.THRESH
 1.0d-12
*CC INPUT 
.CCS
.CCSD
.THRENR
 1.0d-8
.THRLEQ
 1.0d-8
*CCQR
.NOBMAT
.AVERAGE
HYPERPOLARIZABILITY
.DISPCF
  4
**END OF DALTON INPUT
%EOF%
#######################################################################

 

#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >cc_rsp_beta.check
cat >>cc_rsp_beta.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# SCF, MP2 and CCSD energies:
CRIT1=`$GREP "Total SCF   energy: * \-100.008919(8|9)." $log | wc -l`
CRIT2=`$GREP "Total MP2   energy: * \-100.193662(5|6)." $log | wc -l`
CRIT3=`$GREP "Total CCSD  energy: * \-100.1977909." $log | wc -l`
TEST[1]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3` 
CTRL[1]=7
ERROR[1]="ENERGIES NOT CORRECT"


# static CCS hyperpolarizabilities
CRIT1=`$GREP "ZDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000 * ZDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000 * ZDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000 * 16.5732" $log | wc -l`
CRIT2=`$GREP "ZDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000 * XDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000 * XDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000 * ..675553" $log | wc -l`
CRIT3=`$GREP "beta_\|\| * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000 * 10.7546" $log | wc -l`
CRIT4=`$GREP "beta.K * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000 * 10.7546" $log | wc -l`
CRIT5=`$GREP "beta_\|_ * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000 * 3.58487" $log | wc -l`
TEST[2]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5` 
CTRL[2]=5
ERROR[2]="STATIC CCS FIRST HYPERPOLARIZABILITIES NOT CORRECT"

# CCS hyperpolarizability disperion coefficients
CRIT1=`$GREP "2    29.550(1|2)..       3.86137(3|4).       12.84441." $log | wc -l`
CRIT2=`$GREP "4    679.517..       20.9242(2|3).       110.398(8|9)." $log | wc -l`
CRIT3=`$GREP "2    167.255(5|6).       55.7518(5|6).       55.7518(5|6)." $log | wc -l`
CRIT4=`$GREP "4    2169.49(6|7).       241.055(1|2).       241.055(1|2)." $log | wc -l`
CRIT5=`$GREP "beta\(0\)   10.75462" $log | wc -l`
CRIT6=`$GREP "A         2.59199(5|6)" $log | wc -l`
CRIT7=`$GREP "B         5.60352." $log | wc -l`
CRIT8=`$GREP "A       ( |0).835272.." $log | wc -l`
CRIT9=`$GREP "B        4\.15982..         B.     ( \-|\-0)\.707430.." $log | wc -l`
TEST[3]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ $CRIT7 \+ $CRIT8 \+ $CRIT9` 
CTRL[3]=11
ERROR[3]="CCS FIRST HYPERPOLARIZABILITIES DISPERSION COEFFICIENTS NOT CORRECT"


# static CCSD hyperpolarizabilities
CRIT1=`$GREP "ZDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000   ZDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000   ZDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000      15.3808" $log | wc -l`
CRIT2=`$GREP "ZDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000   XDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000   XDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000     ..902738" $log | wc -l`
CRIT3=`$GREP "beta_\|\| * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000 * 10.3117" $log | wc -l`
CRIT4=`$GREP "beta.K * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000 * 10.3117" $log | wc -l`
CRIT5=`$GREP "beta_\|_ * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000 * 3.43726" $log | wc -l`
TEST[4]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5` 
CTRL[4]=5
ERROR[4]="STATIC CCSD FIRST HYPERPOLARIZABILITIES NOT CORRECT"

# CCSD hyperpolarizability disperion coefficients
CRIT1=`$GREP "2    45.4826(6|7).       6.4387(7|8)..       19.52194." $log | wc -l`
CRIT2=`$GREP "4    1253.7(8|9)..       41.9508..       201.162(3|4)." $log | wc -l`
CRIT3=`$GREP "2    188.2000.       62.7333(4|5).       62.7333(4|5)." $log | wc -l`
CRIT4=`$GREP "4    2909.70(5|6).       323.300(6|7).       323.300(6|7)." $log | wc -l`
CRIT5=`$GREP "beta\(0\)   10.31179" $log | wc -l`
CRIT6=`$GREP "A         3.04182(3|4)" $log | wc -l`
CRIT7=`$GREP "B         7.83812." $log | wc -l`
CRIT8=`$GREP "A        1.26875(6|7)." $log | wc -l`
CRIT9=`$GREP "B        7.71987..         B.      \-1.2774(4|5).." $log | wc -l`
TEST[5]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ $CRIT7 \+ $CRIT8 \+ $CRIT9` 
CTRL[5]=11
ERROR[5]="CCSD FIRST HYPERPOLARIZABILITIES DISPERSION COEFFICIENTS NOT CORRECT"

# symmetry of beta tensor:
CRIT1=`$GREP "beta_ms * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000" $log | \
       awk "\\\$5 < 1.0e-12 {print \\\$0}" | wc -l`
CRIT2=`$GREP "beta_ms                                    0" $log | \
       awk "NF==5 && \\\$3+\\\$4+\\\$5 < 1.0e-12 {print \\\$0}" | wc -l`
TEST[6]=`expr $CRIT1 \+ $CRIT2`
CTRL[6]=4
ERROR[6]="SYMMETRY OF HYPERPOLAZABILITY TENSOR NOT CORRECT"

PASSED=1
for i in 1 2 3 4 5 6
do 
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done 

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM 
  exit 1
fi

%EOF%
chmod +x cc_rsp_beta.check
#######################################################################
